In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
import plotly.express as px
In [2]:
size=10000
#facebook
facebook_budget=15*4
conversion=[21,57]
reach=[554,1600]

#ecommerce
ali_price=12.35
shipping=0
selling_price=(ali_price+shipping)+(ali_price+shipping)*1.4

#payment_gate
two_checkout=(selling_price+shipping)*0.035+0.35
stripe=(selling_price+shipping)*0.029+0.3

#arrays
prior_arr=np.empty(size)
posterior_arr=np.empty(size)
ecom_revenu_arr=np.empty(size)
ali_cost_arr=np.empty(size)
two_checkout_cost_arr=np.empty(size)
stripe_cost_arr=np.empty(size)
profit_two_arr=np.empty(size)
profit_stripe_arr=np.empty(size)
    
for i in range(size):
    
    prior=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)))
    posterior=np.random.binomial(np.mean(reach),prior)
        
    ecom_revenu=selling_price*posterior
    ali_cost=(ali_price+shipping)*posterior
    two_checkout_cost=two_checkout*posterior
    stripe_cost=stripe*posterior
    
    profit_two=ecom_revenu-ali_cost-two_checkout_cost-facebook_budget
    profit_stripe=ecom_revenu-ali_cost-stripe_cost-facebook_budget
    
    prior_arr[i]=prior
    posterior_arr[i]=posterior
    ecom_revenu_arr[i]=ecom_revenu
    ali_cost_arr[i]=ali_cost
    two_checkout_cost_arr[i]=two_checkout_cost
    stripe_cost_arr[i]=stripe_cost
    profit_two_arr[i]=profit_two
    profit_stripe_arr[i]=profit_stripe
df=pd.DataFrame(data={"prior_arr":prior_arr,"posterior_arr":posterior_arr,"ecom_revenu_arr":ecom_revenu_arr,
                   "ali_cost_arr":ali_cost_arr,"two_checkout_cost_arr":two_checkout_cost_arr,"stripe_cost_arr":stripe_cost_arr,
                   "profit_two_arr":profit_two_arr,"profit_stripe_arr":profit_stripe_arr})
print("Selling price is:",selling_price)
px.histogram(df,x="profit_two_arr",marginal='box').show()
px.histogram(df,x="prior_arr",marginal='box').show()
px.histogram(df,x="posterior_arr",marginal='box').show()
px.histogram(df,x="ali_cost_arr",marginal='box').show()
Selling price is: 29.64
In [3]:
round(df,3)
Out[3]:
prior_arr posterior_arr ecom_revenu_arr ali_cost_arr two_checkout_cost_arr stripe_cost_arr profit_two_arr profit_stripe_arr
0 0.030 29.0 859.56 358.15 40.235 33.627 401.175 407.783
1 0.032 44.0 1304.16 543.40 61.046 51.021 639.714 649.739
2 0.042 32.0 948.48 395.20 44.397 37.106 448.883 456.174
3 0.040 39.0 1155.96 481.65 54.109 45.223 560.201 569.087
4 0.039 43.0 1274.52 531.05 59.658 49.861 623.812 633.609
... ... ... ... ... ... ... ... ...
9995 0.037 42.0 1244.88 518.70 58.271 48.702 607.909 617.478
9996 0.034 35.0 1037.40 432.25 48.559 40.585 496.591 504.565
9997 0.033 36.0 1067.04 444.60 49.946 41.744 512.494 520.696
9998 0.044 32.0 948.48 395.20 44.397 37.106 448.883 456.174
9999 0.032 33.0 978.12 407.55 45.784 38.265 464.786 472.305

10000 rows × 8 columns

In [4]:
np.mean(conversion)/np.mean(reach)
Out[4]:
0.036211699164345405
In [5]:
beta=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)),size=200)
binom=np.random.binomial(np.mean(reach),beta,size=200)
px.histogram(x=binom,marginal='box').show()
In [6]:
#worst case
size=10000
#facebook
facebook_budget=15*4
conversion=[21]
reach=[1600]

#ecommerce
ali_price=12.35
shipping=0
selling_price=(ali_price+shipping)+(ali_price+shipping)*1.4

#payment_gate
two_checkout=(selling_price+shipping)*0.035+0.35
stripe=(selling_price+shipping)*0.029+0.3

#arrays
prior_arr=np.empty(size)
posterior_arr=np.empty(size)
ecom_revenu_arr=np.empty(size)
ali_cost_arr=np.empty(size)
two_checkout_cost_arr=np.empty(size)
stripe_cost_arr=np.empty(size)
profit_two_arr=np.empty(size)
profit_stripe_arr=np.empty(size)
    
for i in range(size):
    
    prior=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)))
    posterior=np.random.binomial(np.mean(reach),prior)
        
    ecom_revenu=selling_price*posterior
    ali_cost=(ali_price+shipping)*posterior
    two_checkout_cost=two_checkout*posterior
    stripe_cost=stripe*posterior
    
    profit_two=ecom_revenu-ali_cost-two_checkout_cost-facebook_budget
    profit_stripe=ecom_revenu-ali_cost-stripe_cost-facebook_budget
    
    prior_arr[i]=prior
    posterior_arr[i]=posterior
    ecom_revenu_arr[i]=ecom_revenu
    ali_cost_arr[i]=ali_cost
    two_checkout_cost_arr[i]=two_checkout_cost
    stripe_cost_arr[i]=stripe_cost
    profit_two_arr[i]=profit_two
    profit_stripe_arr[i]=profit_stripe
df=pd.DataFrame(data={"prior_arr":prior_arr,"posterior_arr":posterior_arr,"ecom_revenu_arr":ecom_revenu_arr,
                   "ali_cost_arr":ali_cost_arr,"two_checkout_cost_arr":two_checkout_cost_arr,"stripe_cost_arr":stripe_cost_arr,
                   "profit_two_arr":profit_two_arr,"profit_stripe_arr":profit_stripe_arr})
print("Selling price is:",selling_price)
px.histogram(df,x="profit_two_arr",marginal='box',color_discrete_sequence=["#63fa95"]).show()
px.histogram(df,x="prior_arr",marginal='box',color_discrete_sequence=["#63fa95"]).show()
px.histogram(df,x="posterior_arr",marginal='box',color_discrete_sequence=["#63fa95"]).show()
px.histogram(df,x="ali_cost_arr",marginal='box',color_discrete_sequence=["#63fa95"]).show()
Selling price is: 29.64
In [7]:
#worst case
size=10000
#facebook
facebook_budget=15*4
conversion=[21]
reach=[1600]

#ecommerce
ali_price=12.35
shipping=0
selling_price=(ali_price+shipping)+(ali_price+shipping)*0.5

#payment_gate
two_checkout=(selling_price+shipping)*0.035+0.35
stripe=(selling_price+shipping)*0.029+0.3

#arrays
prior_arr=np.empty(size)
posterior_arr=np.empty(size)
ecom_revenu_arr=np.empty(size)
ali_cost_arr=np.empty(size)
two_checkout_cost_arr=np.empty(size)
stripe_cost_arr=np.empty(size)
profit_two_arr=np.empty(size)
profit_stripe_arr=np.empty(size)
    
for i in range(size):
    
    prior=np.random.beta(np.mean(conversion),(np.mean(reach)-np.mean(conversion)))
    posterior=np.random.binomial(np.mean(reach),prior)
        
    ecom_revenu=selling_price*posterior
    ali_cost=(ali_price+shipping)*posterior
    two_checkout_cost=two_checkout*posterior
    stripe_cost=stripe*posterior
    
    profit_two=ecom_revenu-ali_cost-two_checkout_cost-facebook_budget
    profit_stripe=ecom_revenu-ali_cost-stripe_cost-facebook_budget
    
    prior_arr[i]=prior
    posterior_arr[i]=posterior
    ecom_revenu_arr[i]=ecom_revenu
    ali_cost_arr[i]=ali_cost
    two_checkout_cost_arr[i]=two_checkout_cost
    stripe_cost_arr[i]=stripe_cost
    profit_two_arr[i]=profit_two
    profit_stripe_arr[i]=profit_stripe
df=pd.DataFrame(data={"prior_arr":prior_arr,"posterior_arr":posterior_arr,"ecom_revenu_arr":ecom_revenu_arr,
                   "ali_cost_arr":ali_cost_arr,"two_checkout_cost_arr":two_checkout_cost_arr,"stripe_cost_arr":stripe_cost_arr,
                   "profit_two_arr":profit_two_arr,"profit_stripe_arr":profit_stripe_arr})
print("Selling price is:",selling_price)
px.histogram(df,x="profit_two_arr",marginal='box',color_discrete_sequence=["#fa6363"]).show()
px.histogram(df,x="prior_arr",marginal='box',color_discrete_sequence=["#fa6363"]).show()
px.histogram(df,x="posterior_arr",marginal='box',color_discrete_sequence=["#fa6363"]).show()
px.histogram(df,x="ali_cost_arr",marginal='box',color_discrete_sequence=["#fa6363"]).show()
Selling price is: 18.525